package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    /**
     * Spring容器和SpringMVC容器是有层次的（父子容器）
     * Spring容器：service对象+dao对象
     * SpringMVC容器：controller对象，，，，可以引用到Spring容器中的对象
     */


    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/queryAll")
  // @ResponseBody
    public ModelAndView queryAll() throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("userList",resumeService.queryResumeList());
        modelAndView.setViewName("success");
        return modelAndView;
    }
    @RequestMapping("/addShow")
  // @ResponseBody
    public ModelAndView addShow() throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("add");
        return modelAndView;
    }

    @RequestMapping("/editShow")
    // @ResponseBody
    public ModelAndView editShow(Resume resume) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user",resumeService.queryById(resume.getId()));
        modelAndView.setViewName("edit");
        return modelAndView;
    }

    @RequestMapping("/add")
    // @ResponseBody
    public String add(Resume resume) throws Exception {
        resumeService.addResume(resume);
        return "redirect:/resume/queryAll";
    }
    @RequestMapping("/delete")
    // @ResponseBody
    public String delete(Resume resume) throws Exception {
        resumeService.delete(resume.getId());
        return "redirect:/resume/queryAll";
    }



}
